package com.societyGames.codeAlong.state.codeExercise.model
{
	import com.societyGames.utility.BestStringHash;

	public class SyntaxErrorsData
	{
		private var _data:BestStringHash = new BestStringHash();
		
		public static function fromXml(xml:XML):SyntaxErrorsData
		{
			var syntaxErrorsData:SyntaxErrorsData = new SyntaxErrorsData();
			for each (var errorXml:XML in xml.error)
			{
				syntaxErrorsData._data.setValue(errorXml.@start, errorXml.toString());	
			}			
			return syntaxErrorsData;
		}
		
		public function match(text:String):String
		{
			var bestMatch:Object = this._data.findBest(text);
			if (bestMatch != null)
			{
				return String(this._data.findBest(text));
			}
			return null;
		}
	}
}